package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.business.domain.BusCustomerDetail;
import com.ruoyi.business.domain.BusCustomerParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusCustomer;
import com.ruoyi.business.service.IBusCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/business/customer")
public class BusCustomerController extends BaseController
{
    @Autowired
    private IBusCustomerService busCustomerService;

    /**
     * 查询客户信息列表
     */
    //@PreAuthorize("@ss.hasPermi('business:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusCustomer busCustomer)
    {
        startPage();
        List<BusCustomer> list = busCustomerService.selectBusCustomerList(busCustomer);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('business:customer:listDetail')")
    @GetMapping("/listDetail")
    public TableDataInfo listDetail(BusCustomerParam busCustomerParma)
    {
        startPage();
        List<BusCustomerDetail> list = busCustomerService.getCustomerDetail(busCustomerParma);
        return getDataTable(list);
    }


    /**
     * 导出客户信息列表
     */
   // @PreAuthorize("@ss.hasPermi('business:customer:export')")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusCustomerParam busCustomerParma)
    {
        List<BusCustomerDetail> list = busCustomerService.getCustomerDetail(busCustomerParma);
        ExcelUtil<BusCustomerDetail> util = new ExcelUtil<BusCustomerDetail>(BusCustomerDetail.class);
        return util.exportExcel(list, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */
   // @PreAuthorize("@ss.hasPermi('business:customer:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return AjaxResult.success(busCustomerService.selectBusCustomerByCustomerId(customerId));
    }

    /**
     * 新增客户信息
     */
   // @PreAuthorize("@ss.hasPermi('business:customer:add')")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusCustomer busCustomer)
    {
        busCustomer.setCreateBy(getUsername());
        int rows = busCustomerService.insertBusCustomer(busCustomer);
        return rows > 0 ? AjaxResult.success(busCustomer) : AjaxResult.error();
    }

    /**
     * 修改客户信息
     */
   // @PreAuthorize("@ss.hasPermi('business:customer:edit')")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCustomer busCustomer)
    {
        busCustomer.setUpdateBy(getUsername());
        return toAjax(busCustomerService.updateBusCustomer(busCustomer));
    }

    /**
     * 删除客户信息
     */
   // @PreAuthorize("@ss.hasPermi('business:customer:remove')")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(busCustomerService.deleteBusCustomerByCustomerIds(customerIds));
    }
}
